using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace hemsidan.Bases
{
	/// <summary>
	/// Summary description for Page.
	/// </summary>
	public class Page : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			Session.LCID = 1053;
		}




		protected override void OnInit(EventArgs e)
		{
			InitializeComponent();
			//CreateDialogScript();
			base.OnInit (e);
		}

		private void InitializeComponent()
		{    
			CreateHeader();
			CreatePageStructure();
			this.Load += new System.EventHandler(this.Page_Load);
		}



		private void CreateHeader()
		{
            System.Web.UI.HtmlControls.HtmlHead head = this.Header;
            head.Title = "SwiftSite";
            System.Web.UI.HtmlControls.HtmlLink styleLink = new System.Web.UI.HtmlControls.HtmlLink();
            styleLink.Href = Helpers.Settings.VirtualRoot + Helpers.Settings.ActiveStyleSheet;
            styleLink.Attributes.Add("type", "text/css");
            styleLink.Attributes.Add("media", "screen");
            styleLink.Attributes.Add("rel", "stylesheet");
            head.Controls.Add(styleLink);

            System.Web.UI.HtmlControls.HtmlLink rssLink = new System.Web.UI.HtmlControls.HtmlLink();
            rssLink.Href = Helpers.Settings.VirtualRoot + "rss.aspx";
            rssLink.Attributes.Add("type", "application/rss+xml");
            rssLink.Attributes.Add("media", "screen");
            rssLink.Attributes.Add("rel", "alternate");
            rssLink.Attributes.Add("title", Helpers.Settings.SiteTitle + " RSS Feed");
            head.Controls.Add(rssLink);
       }

		private void CreatePageStructure()
		{
			Panel container = new Panel();
			container.ID = "Container";
			Panel header = new Panel();
			header.ID = "Header";

			Panel menu = new Panel();
			menu.ID = "Menu";
			menu.Controls.Add(LoadControl(Helpers.Settings.VirtualRoot + "GUIControls/MainMenu.ascx"));
			menu.Controls[0].ID = "CtlMenu";


			Panel content = new Panel();
			content.ID = "Content";

			Panel footer = new Panel();
			footer.ID = "Footer";

			while (this.Controls[3].Controls.Count > 0)
			{
				Control c = this.Controls[3].Controls[0];
				content.Controls.Add(c);
				this.Controls[3].Controls.Remove(c);
			}
			
			container.Controls.Add(header);
			container.Controls.Add(menu);
			container.Controls.Add(content);
			container.Controls.Add(footer);
			this.Form.Controls.Add(container);
		}

		protected string UserId
		{
			get 
			{
				if (this.Session["UserId"] == null)
					  return null;
				  else
					  return (string)this.Session["UserId"];
			}
			set
			{
				this.Session["UserId"] = value;
			}
		}
	}
}